home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / tools / dvi_300b / treiber / sources / img.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  4KB  |  201 lines

  1. #include <portab.h>
  2.  
  3. #include <stdio.h>
  4.  
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <tos.h>
  8.  
  9. #include "treiber.h"
  10.  
  11.  
  12. long    max_puffer_laenge=0; /* Nicht spoolen */
  13.  
  14.  
  15. /* Versucht Zeile zu Komprimieren */
  16. WORD    compress_img_run( UBYTE *ziel, UBYTE *p, WORD *limit )
  17. {
  18.     UBYTE    i;
  19.  
  20.         /* Sonst getrennt */
  21.     if(  p[0]==0xFF  ||  p[0]==0  )
  22.     {
  23.         for(  i=1;  p[i]==p[0]  &&  i<*limit  &&  i<0x7F;  i++  )
  24.             ;
  25.         ziel[0] = (0x80 & p[0]) | i;
  26.         (*limit) -= i;
  27.         return 1;
  28.     }
  29.     else
  30.     {
  31.         /* Abstand zum nächsten Ungleichen... */
  32.         for(  i=0;  p[i]!=0  &&  p[i]!=0xFF  &&  i<127  &&  i<*limit;  i++  )
  33.             ziel[i+2] = p[i];
  34.         ziel[0] = 0x80;
  35.         ziel[1] = i;
  36.         (*limit) -= i;
  37.         return i+2;
  38.     }
  39. }
  40. /* 17.1.93 */
  41.  
  42.  
  43. typedef struct {
  44.     unsigned version;
  45.     unsigned headlen;
  46.     unsigned nplanes;
  47.     unsigned patlen;
  48.     unsigned pixelw;
  49.     unsigned pixelh;
  50.     unsigned linew;
  51.     unsigned lines;
  52. /*    unsigned palette[16]; Sind eh monochrom */
  53. } IMGHEADER;
  54.  
  55.  
  56. UBYTE        line[8192];
  57. UBYTE        tmp_zeile[8192];
  58.  
  59. #ifdef SHOW_PRT
  60. extern char    *disp_status;
  61. extern char    *char_status;
  62. extern char    rot_status;
  63. #endif
  64.  
  65. WORD    drucke_quer( UBYTE *p, LONG start_x, LONG weite, LONG hoehe, LONG h_dpi, LONG v_dpi, WORD th, WORD flag )
  66. {
  67.     IMGHEADER    hdr;
  68.     LONG            max_spalte, wweite;
  69.     LONG            rep, i, x;
  70.     WORD            lz;
  71.     UBYTE            and_it;
  72.  
  73.         /* Header */
  74.     hdr.version = 1;
  75.     hdr.headlen = (WORD)sizeof(IMGHEADER)>>1;
  76.     hdr.nplanes = 1;
  77.     hdr.patlen = 2;
  78.         /* Grafikauflösung festlegen */
  79.     hdr.pixelw = (WORD)((25400L+v_dpi/2)/v_dpi);
  80.     hdr.pixelh = (WORD)((25400L+h_dpi/2)/h_dpi);
  81.         /* Grafikweite festlegen */
  82.     hdr.linew = (WORD)hoehe;
  83.     hdr.lines = (WORD)(start_x+weite);
  84.     Fseek( 0L, th, 0 );
  85.     Fwrite( th, sizeof(IMGHEADER), &hdr );
  86.     Fseek( 0L, th, 2 );
  87.  
  88.     hoehe--;
  89.     max_spalte = (hoehe+7)>>3;
  90.     hoehe &= 7;
  91.     if(  hoehe  )
  92.         and_it = ~(WORD)(0x00FFL << hoehe);
  93.     else
  94.         and_it = 0x00FF;
  95.     x = 0;
  96.     wweite = (weite+15)>>4;
  97.     wweite *= 2;
  98.  
  99.     for(  i=0;  (flag&2)  &&  x<weite;  x++  )
  100.     {
  101. #ifdef SHOW_PRT
  102.         if(  (x%128)==0  )
  103.         {
  104.             disp_status[2] = char_status[rot_status++];
  105.             rot_status &= 3;
  106.             Cconws( disp_status );
  107.         }
  108. #endif
  109.         drehe_90( p, tmp_zeile, wweite, max_spalte-1, x );
  110.          Fwrite( th, 4L, "\000\000\377\001" );
  111.  
  112.         /* Eine Zeile in die Datei! */
  113.         tmp_zeile[0] &= and_it;
  114.         rep = lz = (WORD)max_spalte;
  115.         i = 0;
  116.         while(  lz>0  )
  117.             i += compress_img_run( line+i, tmp_zeile+rep-lz, &lz );
  118.         Fwrite( th, (LONG)i, line );
  119.      }
  120.     return 0;
  121. }
  122. /* 7.10.95 */
  123.  
  124.  
  125. /* Schreibe in IMG-Datei, auch in mehreren Teilen */
  126. WORD    drucke( UBYTE *p, LONG start_y, LONG weite, LONG max_zeile, LONG h_dpi, LONG v_dpi, WORD th, WORD flag, WORD quer, UBYTE *opt )
  127. {
  128.     IMGHEADER    hdr;
  129.     WORD            max_spalte, zeile, lz;
  130.     WORD            rep, i;
  131.     UBYTE            l;
  132.  
  133.     (void)opt;    /* ignorieren */
  134.  
  135.     if(  th<=5  )
  136.     {
  137.         Cconws( "Bitte Dateinamen angeben!\007" );
  138.         return -1;
  139.     }
  140.     if(  flag==4  )
  141.         return 0;
  142.  
  143.     if(  quer  )
  144.         return drucke_quer( p, start_y, weite, max_zeile, h_dpi, v_dpi, th, flag );
  145.  
  146.         /* Header */
  147.     hdr.version = 1;
  148.     hdr.headlen = (WORD)sizeof(IMGHEADER)/2;
  149.     hdr.nplanes = 1;
  150.     hdr.patlen = 2;
  151.         /* Grafikauflösung festlegen */
  152.     hdr.pixelw = (WORD)((25400L+h_dpi/2)/h_dpi);
  153.     hdr.pixelh = (WORD)((25400L+v_dpi/2)/v_dpi);
  154.         /* Grafikweite festlegen */
  155.     hdr.linew = (WORD)weite;
  156.     hdr.lines = (WORD)(start_y+max_zeile);
  157.     Fseek( 0L, th, 0 );
  158.     Fwrite( th, sizeof(IMGHEADER), &hdr );
  159.     Fseek( 0L, th, 2 );
  160.  
  161.     max_spalte = (WORD)(weite+7)>>3;
  162.     zeile = 0;
  163.     weite = (weite+15)>>4;
  164.     weite *= 2;
  165.  
  166.     while(  zeile<max_zeile  &&  (flag&2)  )
  167.      {
  168. #ifdef SHOW_PRT
  169.         if(  (zeile%256)==0  )
  170.         {
  171.             disp_status[2] = char_status[rot_status++];
  172.             rot_status &= 3;
  173.             Cconws( disp_status );
  174.         }
  175. #endif
  176.  
  177.         /* Zeilenkopf */
  178.         /* gleiche Zeilen komprimieren */
  179.          for(  l=1;  0==memcmp( p, p+weite, max_spalte )  &&  zeile<max_zeile  &&  l<255;  l++, zeile++  )
  180.              p += weite;
  181.          Fwrite( th, 3L, "\0\0\xFF" );
  182.         Fwrite( th, 1L, &l );
  183.  
  184.             /* Eine Zeile in die Datei! */
  185.         rep = lz = max_spalte;
  186.         i = 0;
  187.             /* Wir komprimieren (es bleibt auch nichts übrig) */
  188.         while(  lz>0  )
  189.             i += compress_img_run( line+i, p+rep-lz, &lz );
  190.         Fwrite( th, (LONG)i, line );
  191.  
  192.         p += weite;
  193.         zeile++;
  194.     }
  195.     /* Sollte immer gut gehen! (d.h. kein File zum Drucken!) */
  196.     return Fclose( th );
  197. }
  198. /* 22.1.93 */
  199. /* 7.10.95 */
  200.  
  201.